package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/encoding")
public class EncodingServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //2、request对象设置字符集编码
        req.setCharacterEncoding("UTF-8");
        String username = req.getParameter("username");
        System.out.println("username:"+username);
        //1、String编码和解码
        String name=new String(username.getBytes("ISO-8859-1"),"UTF-8");
        System.out.println("name:"+name);

    }
}
